import { request } from "@/utils/service"

export interface ISearchDepartmentReq {
  departName?: string
  departCode?: string
}

export interface IDeparment extends ISearchDepartmentReq {
  id?: number
  isCompany?: boolean
  manager?: number
  sort?: number
  parentId?: number
  createUser?: number
  createTime?: string
  updateUser?: number
  updateTime?: string
  tenantId?: number
}

export function getDepartmentListApi(params: ISearchDepartmentReq) {
  return request({
    url: "system/department/list",
    method: "get",
    params
  })
}

export function createDepartmentApi(data: IDeparment) {
  return request({
    url: "system/department/create",
    method: "post",
    data
  })
}

export function batchCreateDepartmentApi(data: IDeparment[]) {
  return request({
    url: "system/department/batchCreate",
    method: "post",
    data
  })
}

export function updateDepartmentApi(data: IDeparment) {
  return request({
    url: "system/department/update",
    method: "put",
    data
  })
}

export function deleteDepartmentApi(data: { id: string; recursive: number }) {
  return request({
    url: "system/department/" + data.id,
    method: "delete",
    params: { recursive: data.recursive }
  })
}
